package com.upcode.weighing.detect.controller;

import com.upcode.weighing.base.controller.BaseController;
import com.upcode.weighing.detect.service.DetectStatsService;
import com.upcode.weighing.log.OpsLog;
import com.upcode.weighing.vo.req.DetectStatsQueryParam;
import com.upcode.weighing.vo.resp.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/detectstats")
@Api(value = "/detectstats",description = "检测统计接口",produces = MediaType.ALL_VALUE,tags = {"统计接口"})
public class DetectStatsController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(DetectStatsController.class);
    @Autowired
    private DetectStatsService detectStatsService;
    /**
     * 检测总览统计
     */
    @OpsLog(operation = "检测统计/检测总览" ,type = 1)
    @PostMapping("/detectOverview")
    @ApiOperation(value = "检测总览",notes = "")
    public ResponseEntity<BaseResponseVo<DetectOverviewStats>> detectOverview(@RequestBody DetectStatsQueryParam detectStatsQueryParam){
        if(detectStatsQueryParam.getStartTime()!=null && detectStatsQueryParam.getStartTime().length()<19){
            detectStatsQueryParam.setStartTime(detectStatsQueryParam.getStartTime()+" 00:00:00");
        }
        if(detectStatsQueryParam.getEndTime()!=null && detectStatsQueryParam.getEndTime().length()<19){
            detectStatsQueryParam.setEndTime(detectStatsQueryParam.getEndTime()+" 23:59:59");
        }
        DetectOverviewStats detectOverviewStats = detectStatsService.overviewStats(detectStatsQueryParam);
        return HttpResponse.success(detectOverviewStats);
    }
    /**
     * 车型分析
     */
    @OpsLog(operation = "检测统计/车型分析" ,type = 1)
    @PostMapping("/vehicleTypeStats")
    @ApiOperation(value = "车型分析",notes = "")
    public  ResponseEntity<BaseResponseVo<List<VehicleTypeStats>>> vehicleTypeStats(@RequestBody DetectStatsQueryParam detectStatsQueryParam){
        if(detectStatsQueryParam.getStartTime()!=null && detectStatsQueryParam.getStartTime().length()<19){
            detectStatsQueryParam.setStartTime(detectStatsQueryParam.getStartTime()+" 00:00:00");
        }
        if(detectStatsQueryParam.getEndTime()!=null && detectStatsQueryParam.getEndTime().length()<19){
            detectStatsQueryParam.setEndTime(detectStatsQueryParam.getEndTime()+" 23:59:59");
        }
        List<VehicleTypeStats> detectOverviewStats = detectStatsService.vehTypeStats(detectStatsQueryParam);
        return HttpResponse.success(detectOverviewStats);
    }
    /**
     * 趋势分析
     */
    @OpsLog(operation = "检测统计/趋势分析" ,type = 1)
    @PostMapping("/tendencyStats")
    @ApiOperation(value = "趋势分析",notes = "")
    public  ResponseEntity<BaseResponseVo< Map<String, Object>>> tendencyStats(@RequestBody DetectStatsQueryParam detectStatsQueryParam){
        if(detectStatsQueryParam.getStartTime()!=null && detectStatsQueryParam.getStartTime().length()<19){
            detectStatsQueryParam.setStartTime(detectStatsQueryParam.getStartTime()+" 00:00:00");
        }
        if(detectStatsQueryParam.getEndTime()!=null && detectStatsQueryParam.getEndTime().length()<19){
            detectStatsQueryParam.setEndTime(detectStatsQueryParam.getEndTime()+" 23:59:59");
        }
        Map<String, Object> tendencyStatsMap = detectStatsService.tendencyStats(detectStatsQueryParam);
        return HttpResponse.success(tendencyStatsMap);
    }


    /**
     * 超限幅度分析
     */
    @OpsLog(operation = "检测统计/超限幅度分析" ,type = 1)
    @PostMapping("/overRangeStats")
    @ApiOperation(value = "超限幅度分析",notes = "")
    public  ResponseEntity<BaseResponseVo<List<OverRangeStats>>> overRangeStats(@RequestBody DetectStatsQueryParam vo){
        if(vo.getStartTime()!=null && vo.getStartTime().length()<19){
            vo.setStartTime(vo.getStartTime()+" 00:00:00");
        }
        if(vo.getEndTime()!=null && vo.getEndTime().length()<19){
            vo.setEndTime(vo.getEndTime()+" 23:59:59");
        }
        List<OverRangeStats> overRangeStatsList=detectStatsService.overRangeStats(vo);
        return HttpResponse.success(overRangeStatsList);
    }

    /**
     * 超限幅度分析
     */
    @OpsLog(operation = "检测统计/属地分析" ,type = 1)
    @PostMapping("/belongAddrStats")
    @ApiOperation(value = "属地分析",notes = "")
    public  ResponseEntity<BaseResponseVo<List<BelongAddrStats>>> belongAddrStats(@RequestBody DetectStatsQueryParam vo){
        if(vo.getStartTime()!=null && vo.getStartTime().length()<19){
            vo.setStartTime(vo.getStartTime()+" 00:00:00");
        }
        if(vo.getEndTime()!=null && vo.getEndTime().length()<19){
            vo.setEndTime(vo.getEndTime()+" 23:59:59");
        }
        List<BelongAddrStats> overRangeStatsList=detectStatsService.belongAddrStats(vo);
        return HttpResponse.success(overRangeStatsList);
    }

    /**
     * 检测点统计
     */
    @OpsLog(operation = "检测统计/检测点检测统计" ,type = 1)
    @PostMapping("/pointDetectStats")
    @ApiOperation(value = "检测点检测统计",notes = "")
    public  ResponseEntity<BaseResponseVo<List<DetectPointDetectStats>>> pointDetectStats(@RequestBody DetectStatsQueryParam vo){
        if(vo.getStartTime()!=null && vo.getStartTime().length()<19){
            vo.setStartTime(vo.getStartTime()+" 00:00:00");
        }
        if(vo.getEndTime()!=null && vo.getEndTime().length()<19){
            vo.setEndTime(vo.getEndTime()+" 23:59:59");
        }
        List<DetectPointDetectStats> detectPointDetectStatsList=detectStatsService.queryDetectPointStats(vo);
        return HttpResponse.success(detectPointDetectStatsList);
    }

    /**
     * 检测点统计
     */
    @OpsLog(operation = "检测统计/检测点统计" ,type = 1)
    @PostMapping("/pointStats")
    @ApiOperation(value = "检测点统计",notes = "")
    public  ResponseEntity<BaseResponseVo<DetectPointStats>> pointStats(@RequestBody DetectStatsQueryParam vo){
        DetectPointStats detectPointStats = detectStatsService.queryPointStats(vo);
        return HttpResponse.success(detectPointStats);
    }
}
